<?php
/**
 * Image.php
 *
 * @copyright   2023 thingsworld.com.cn - All Rights Reserved
 * @link        http://thingsworld.com.cn/
 * @author      stiffer.chen <chenl@thingsworld.com.cn>
 * @created     2023-02-16 03:19:50
 * @modified    2023-02-16 03:19:50
 *
 */

namespace App\Models\Event;

use App\Models\BaseModel;
use App\Services\ImageServ;

class Image extends BaseModel
{
    public $timestamps = false;
    protected $table = 'event_image';

    protected $rules = [

    ];

    protected $fillable = [
        'event_id',
        'image',
    ];

    protected $appends = [
        'img_url',
        'name'
    ];

    public function getImgUrlAttribute()
    {
        $img = $this->image;
        $url = (new ImageServ($img))->getUrl();
        return $url;
    }

    public function getNameAttribute()
    {
        $img = $this->img;
        if (!$img) {
            return '';
        }
        $imgArr = explode('/', $img);
        return $imgArr[count($imgArr) - 1];
    }
}